package com.vooda.business_admin.controller.homePage;

import com.vooda.business_admin.common.BaseController;
import com.vooda.business_admin.common.ReqDataTableDto;
import com.vooda.business_admin.common.RspDataTableDto;
import com.vooda.business_admin.entity.HomePage;
import com.vooda.business_admin.entity.Market;
import com.vooda.business_admin.entity.Store;
import com.vooda.business_admin.service.HomePageService;
import com.vooda.business_admin.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 商家
 */
@RestController
@RequestMapping("/store")
public class StoreController extends BaseController{

    @Autowired
    private StoreService storeService;

    @GetMapping("/getStoreList")
    public List<Store> getStoreList(){
        return storeService.getStoreList();
    }

    /**
     * 获取所有商家列表
     * @param dataTableDTO
     * @return
     */
    @GetMapping("/getAllList")
    public RspDataTableDto<Store> getAllList(ReqDataTableDto dataTableDTO,
                                              @RequestParam(value = "market",required = false) String marketId){

        return storeService.findAllStoreList(dataTableDTO,marketId);

    }

    /**
     *查单个商家
     * @return
     */
    @GetMapping("/editStore/{id}")
    public Store editRole(HttpServletRequest request, @PathVariable("id") Long id){
        return storeService.selectByPrimaryKey(id);

    }

    /**
     *保存超市
     * @return
     */
    @PostMapping("/saveStore")
    public String saveRole(Store store, @RequestParam(required = false) MultipartFile image){

        return storeService.saveStore(store,image);


    }

    /**
     * 删除超市
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/removeStore/{id}")
    public String removeArticle(HttpServletRequest request, @PathVariable("id") Long id){
        return storeService.deleteByPrimaryKey(id);

    }

    /**
     * 修改封面图片
     * @param imageUpload
     * @param id
     * @return
     */
    @PostMapping("/updateImage/{id}")
    public void updateImage(@RequestParam("imageUpload") MultipartFile imageUpload, @PathVariable("id") Long id){

        storeService.updateImage(imageUpload,id);

    }


}
